//
// Created by Martin on 2021/10/29.
//

#include <iostream>
#include <queue>
#include <vector>
#include <stdio.h>
#include <stdlib.h>

#define M_MAX     30000

using namespace std;

int main()
{
    priority_queue<int> q1; // 大堆
    priority_queue<int, vector<int>, greater<int> > q2; // 小堆
    int n, m, x;

    scanf("%d%d", &m, &n);
    if (m > M_MAX || n < 0 || n > m) {
        printf("invalid input N = %d, M = %d\n", n, m);
        exit(1);
    }

    int *a = new int[m + 1];
    for (int i = 1; i <= m ; ++i) {
        scanf("%d", &a[i]);
    }

    int cnt = 1;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &x);
        while (cnt <= x) {
            if (!q1.empty() && a[cnt] < q1.top()) {
                q2.push(q1.top());
                q1.pop();
                q1.push(a[cnt]);
            }
            else {
                q2.push(a[cnt]);
            }

            cnt++;
        }

        printf("%d\n", q2.top());
        q1.push(q2.top());
        q2.pop();
    }

    delete[] a;
    return 0;
}